import { PureComponent } from 'react';
import moment from 'moment';
import '@/assets/iconfont/iconfont';
import styles from './StaffInfoList.less';
import SelectDeptTree from '@/components/SelectDeptTree';
import { dicTextByCodePcode,dicListByPcode } from '@/utils/dictionary'
import {
    Row,
    Col,
    Form,
    Input,
    Select,
    Modal,
    DatePicker,
    Button,
    Upload,
    Cascader
} from 'antd';
const FormItem = Form.Item;
const { Option } = Select;
const formItemLayout = {
 	labelCol: { span: 10 },
   	wrapperCol: { span: 14 },
};

@Form.create()
class UpdateForm extends PureComponent {

	constructor(props) {
		super(props);
		// const staffAge = moment().format('YYYY') - moment(props.values.date_of_birth).format('YYYY');
    this.state = {
			formVals: {
        za0100: props.values.za0100,
        id: props.values.id,
        a1701: props.values.a1701,
        a1704: props.values.a1704,
        a1707_1: props.values.a1707_1,
        a1707_2: props.values.a1707_2,
        a1709: props.values.a1709,
        a1710: props.values.a1710,
        a1713: props.values.a1713,
        a1715: props.values.a1715,
        a1717: props.values.a1717,
        a1719: props.values.a1719,
        a1721: props.values.a1721,
        a1723: props.values.a1723,
        a1725: props.values.a1725,
        a1728: props.values.a1728,
        a1729: props.values.a1729,
        a1712: props.values.a1712

			},
			getDeptTreeBySelectTree: "",
		};

	}


	componentWillReceiveProps(nextProps) {
		// if(undefined != nextProps.values && nextProps.values !== this.props.values) {
		// 	const staffAge = moment().format('YYYY') - moment(nextProps.values.date_of_birth).format('YYYY');
		//     this.setState({
		//       formVals: nextProps.values,
		//       imageUrl: nextProps.values.photo_sign,
		//       photoNum: nextProps.values.photo_sign?1:0,
		//       ageNum: staffAge?staffAge:null
		//     });
		// }

	}

	selectedDeptTreeValue = (deptRecord) => {
		this.setState({
			getDeptTreeBySelectTree: deptRecord
		})
	}



 	birthChange = value => {
		this.setState({
			ageNum: moment().format('YYYY') - value.format('YYYY')

		})
	}

	handleLocalUpdate = (event) => {
		event.preventDefault();
		const { form,handleSubmitSubsetInfo } = this.props;
		const { formVals: oldValue,getDeptTreeBySelectTree } = this.state;
		form.validateFields((err, fieldsValue) => {
			if(err) return;
			form.resetFields();
			const formVals = {
				...oldValue,
				...fieldsValue
			};
			this.setState({
				formVals,
			});

			/* if(getDeptTreeBySelectTree) {
				formVals.dept_id = getDeptTreeBySelectTree.triggerNode.props.dataRef.dept_id;
				formVals.dept = getDeptTreeBySelectTree.triggerNode.props.dataRef.title;
			}

			if(formVals.post) {
				formVals.post_id = formVals.post.key;
				formVals.post_name = formVals.post.label;
			} */

			if(formVals.a1704) {
      			formVals.a1704 = moment(formVals.a1704._d).format("YYYY-MM-DD");
      		}
			// formVals.file = this.state.file;
			handleSubmitSubsetInfo(formVals,"update_for_staff_checkInfo");

		});
	};

  render() {
    const {
    	form: {getFieldDecorator},
    	falg,
      spinIndex,
    	cancelEditJobInfo,
    	cascaderList,
    	values,
    	selectDeptTree,
    	postForUser,
      requestModelName,
      dispatch
    } = this.props;

    const parentDeptTreeMethod = {
		dispatch: dispatch,
		selectDeptTree: selectDeptTree,
		selectedDeptTreeValue: this.selectedDeptTreeValue,
		requestModelName: requestModelName,
	}

    const { formVals,imageUrl,photoNum } = this.state;
    // 多选处理 TODO
    let newPlace = [];
    if(values.place_of_origin && values.place_of_origin != "null" ) {
    	const place = JSON.parse(values.place_of_origin);
    	newPlace = place.map((item,index) => item = item + '');
    }
	return (
		<div>
			{falg?(
				<Form  onSubmit={this.handleLocalUpdate}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="考核年度">
			              {getFieldDecorator('a1701', {
			              rules: [{ required: true, message: '请输入1-10个字符',max: 10}],
			              initialValue: formVals.a1701,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

              <Col md={12} sm={24}>
                <FormItem  label="考核结论">
                    {getFieldDecorator('a1723', {
                      rules: [{ required: false, message: '请选择'}],
                      initialValue: formVals.a1723,
                    })(
                      <Select labelInValue placeholder="请选择" style={{ width: '100%' }}>
                      	{dicListByPcode('AE') != undefined?dicListByPcode('AE').map((item,index) => {
                      		return <Option value={item.DICTVALUE}>{item.DESCRIPTION}</Option>
                      	}):null}
                      </Select>
                    )}
                </FormItem>
              </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="考核日期">
			              {getFieldDecorator('a1704',{
			              	initialValue: formVals.a1704?moment(formVals.a1704):null,
			              	    })(<DatePicker  format="YYYY-MM-DD" style={{ width: '100%' }} placeholder="请选择"/>)}
			              	</FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="考核单位名称">
			              {getFieldDecorator('a1707_1', {
			              rules: [{ required: false, message: '1-10个字符'}],
			              initialValue: formVals.a1707_1,
			              })(<Input placeholder="1-10个字符"/>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="考核单位代码">
			              {getFieldDecorator('a1707_2', {
			              rules: [{ required: false, message: '1-10个字符'}],
			              initialValue: formVals.a1707_2,
			              })(
			              	<Input placeholder="1-10个字符"/>
			              )}
			          </FormItem>
			        </Col>

			        <Col md={12} sm={24}>
			          <FormItem  label="参加考核的应到人数">
			              {getFieldDecorator('a1710',{
			                rules: [{ required: false, message: '1-10个字符！'}],
                      initialValue: formVals.a1710,
			              })(
			              	<Input placeholder="1-10个字符"/>
			              )}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="实到考核人数">
			              {getFieldDecorator('a1712', {
			              rules: [{ required: false, message: '1-10个字符'}],
			              initialValue: formVals.a1712,
			              })(
                      <Input placeholder="1-10个字符"/>
                    )}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="考核优秀得票数">
			              {getFieldDecorator('a1713', {
                    rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1713,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>


			        <Col md={12} sm={24}>
			          <FormItem  label="考核称职(合格)得票数">
			              {getFieldDecorator('a1715', {
			              rules: [{ required: false, message: '1-40个字符'}],
			              initialValue: formVals.a1715,
			              })(<Input placeholder="1-40个字符" />)}
			          </FormItem>
			        </Col>

			       	<Col  md={12} sm={24}>
			       	  <FormItem  label="考核基本称职(基本合格)得票数">
			       	      {getFieldDecorator('a1717', {
			       	        rules: [{ required: false, message: '1-40个字符'}],
                      initialValue: formVals.a1717,
			       	        })(<Input placeholder="1-40个字符" />)}
			       	        </FormItem>
			       	</Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col md={12} sm={24}>
			    	  <FormItem  label="考核不称职(不合格)得票数">
			    	      {getFieldDecorator('a1719', {
			    	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1719,
			    	        })(
			    	       <Input placeholder="1-40个字符" />
			    	      )}
			    	  </FormItem>
			    	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="弃权票数">
                  {getFieldDecorator('a1721', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1721,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col md={12} sm={24}>
          	  <FormItem  label="考核组成员">
          	      {getFieldDecorator('a1709', {
          	        rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1709,
          	        })(
          	       <Input placeholder="1-40个字符" />
          	      )}
          	  </FormItem>
          	</Col>

            <Col md={12} sm={24}>
              <FormItem  label="考核备注">
                  {getFieldDecorator('a1725', {
                    rules: [{ required: false, message: '1-40个字符'}],
                    initialValue: formVals.a1725,
                    })(
                    <Input placeholder="1-40个字符" />
                  )}
              </FormItem>
            </Col>
          </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>
          	<Col md={12} sm={24}>
                  <Button
                  	size="large"
                  	style={{marginRight: '10px'}}
                  	onClick={()=> {
                  		const { form } = this.props;
          				form.resetFields();
                  		cancelEditJobInfo(spinIndex);
                  	}}>
                  	取消
                 	</Button>
                  <Button size="large" type="primary" htmlType="submit">保存</Button>
              </Col>
          </Row>

			  </Form>
			):(
			<Form  {...formItemLayout}>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="考核年度">
			              {getFieldDecorator('a1701')(<span>{formVals.a1701}</span>)}
			          </FormItem>
			        </Col>

					<Col md={12} sm={24}>
			          <FormItem  label="考核结论">
			              {getFieldDecorator('a1723')(<span>{formVals.a1723}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="考核日期">
			              {getFieldDecorator('a1704')(<span>{formVals.a1704?moment(formVals.a1704).format('YYYY-MM-DD'):null}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="考核单位名称">
			              {getFieldDecorator('a1707_1')(<span>{formVals.a1707_1}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

					<Col md={12} sm={24}>
			          <FormItem  label="考核单位代码">
			              {getFieldDecorator('a1707_2')(<span>{formVals.a1707_2}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="参加考核的应到人数">
			              {getFieldDecorator('a1710')(<span>{formVals.a1710}
			              	</span>)}
			          </FormItem>
			        </Col>


			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="实到考核人数">
			              {getFieldDecorator('a1712')(<span>{formVals.a1712}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="考核优秀得票数">
			              {getFieldDecorator('a1713')(<span>{formVals.a1713}</span>)}
			          </FormItem>
			        </Col>

			    </Row>

			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			        <Col md={12} sm={24}>
			          <FormItem  label="考核称职(合格)得票数">
			              {getFieldDecorator('a1715')(<span>{formVals.a1715}</span>)}
			          </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="考核基本称职(基本合格)得票数">
			              {getFieldDecorator('a1717')(<span>{formVals.a1717}</span>)}
			          </FormItem>
			        </Col>

			    </Row>
			    <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

			    	<Col  md={12} sm={24}>
				        <FormItem  label="考核不称职(不合格)得票数">
				            {getFieldDecorator('a1719')(<span>{formVals.a1719}</span>)}
				        </FormItem>
			        </Col>
			        <Col md={12} sm={24}>
			          <FormItem  label="弃权票数">
			              {getFieldDecorator('a1721')(<span>{formVals.a1721}
			              </span>)}
			          </FormItem>
			        </Col>

			    </Row>

          <Row gutter={{ md: 8, lg: 24, xl: 48 }}>

          	<Col  md={12} sm={24}>
                <FormItem  label="考核组成员">
                    {getFieldDecorator('a1709')(<span>{formVals.a1709}</span>)}
                </FormItem>
              </Col>
              <Col md={12} sm={24}>
                <FormItem  label="考核备注">
                    {getFieldDecorator('a1725')(<span>{formVals.a1725}
                    </span>)}
                </FormItem>
              </Col>

          </Row>

			  </Form>
			)}
		</div>


	);
  }

}

export default UpdateForm;
